package com.ruoyi.qd.controller;

import cn.hutool.core.lang.func.LambdaUtil;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.qd.vo.UniAppSelectRes;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.ruoyi.common.core.domain.entity.table.SysDeptTableDef.SYS_DEPT;

/**
 * 系统Controller-清大专用
 *
 * @author tushiguang
 * @date 2024-07-28
 */
@Anonymous
@RestController
@RequestMapping("/qd/system")
public class QdSystemController extends BaseController {

    /**
     * 获取用户预约系统部门集合
     */
    @GetMapping("/getDeptList")
    public AjaxResult getDeptList() {
        List<UniAppSelectRes> uniAppSelectRes = SysDept.create()
                .select(
                        SYS_DEPT.DEPT_ID.as(LambdaUtil.getFieldName(UniAppSelectRes::getValue)),
                        SYS_DEPT.DEPT_NAME.as(LambdaUtil.getFieldName(UniAppSelectRes::getText))
                )
                .where(SysDept::getParentId).eq(100L)
                .orderBy(SYS_DEPT.ORDER_NUM.asc())
                .listAs(UniAppSelectRes.class);
        return success(uniAppSelectRes);
    }
}
